// import com.alibaba.druid.sql.ast.SQLName;
// import com.alibaba.druid.sql.ast.SQLStatement;
// import com.alibaba.druid.sql.ast.statement.SQLForStatement;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "OracleForStatement.h"
#include "../../../../ast/SQLName.h"
#include "../../../../ast/SQLStatement.h"
#include "../../visitor/OracleASTVisitor.h"
#include "../../../../visitor/SQLASTVisitor.h"
#include "../../../../../utils/instanceof.h"
#include "../../../../../utils/listTran.h"

// @Override
void OracleForStatement::accept0(SQLASTVisitor_ptr v)
{
  if (instanceof <SQLASTVisitor, OracleASTVisitor>(v))
  {
    accept0(std::dynamic_pointer_cast<OracleASTVisitor>(v));
    return;
  }

  SQLForStatement::accept0(v);
}

// @Override
void OracleForStatement::accept0(OracleASTVisitor_ptr v)
{
  if (v->visit(SharedObject(OracleForStatement)))
  {
    acceptChild(v, index);
    acceptChild(v, range);
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLStatement, SQLObject>(statements);
    acceptChild(v, tmp1);
  }
  v->endVisit(SharedObject(OracleForStatement));
}

BOOL_ptr OracleForStatement::isAll()
{
  return all;
}

void OracleForStatement::setAll(BOOL_ptr all)
{
  this->all = all;
}

SQLName_ptr OracleForStatement::getEndLabel()
{
  return endLabel;
}

void OracleForStatement::setEndLabel(SQLName_ptr endLabel)
{
  if (endLabel != nullptr)
  {
    endLabel->setParent(SharedObject(OracleForStatement));
  }
  this->endLabel = endLabel;
}

SQLObject_ptr OracleForStatement::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<OracleForStatement>(new OracleForStatement());
  std::shared_ptr<OracleForStatement> x = std::dynamic_pointer_cast<OracleForStatement>(clone_tmp);
  // OracleForStatement x = new OracleForStatement();
  if (index != nullptr)
  {
    x->setIndex(std::dynamic_pointer_cast<SQLName>(index->clone()));
  }
  if (range != nullptr)
  {
    x->setRange(std::dynamic_pointer_cast<SQLExpr>(range->clone()));
  }
  for (SQLStatement_ptr stmt : *statements)
  {
    SQLStatement_ptr stmt2 = std::dynamic_pointer_cast<SQLStatement>(stmt->clone());
    stmt2->setParent(x);
    x->statements->push_back(stmt2);
  }
  x->all = all;
  if (endLabel != nullptr)
  {
    x->setEndLabel(std::dynamic_pointer_cast<SQLName>(endLabel->clone()));
  }
  return x;
}
